package com.yixun.qfbao.controller;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yixun.common.controller.BaseController;
import com.yixun.qfbao.controller.vo.SmsHistoryVo;
import com.yixun.qfbao.model.Company;
import com.yixun.qfbao.model.SmsHistory;
import com.yixun.qfbao.model.dto.SmsHistoryDto;
import com.yixun.qfbao.model.enums.SendStatusEnum;
import com.yixun.qfbao.service.CompanyService;
import com.yixun.qfbao.service.ExportService;
import com.yixun.qfbao.service.SmsHistoryService;

/**
 * [文件名称]<br>
 * ExportController.java<br>
 * <br>
 * [文件描述]<br>
 * 导出 Controller<br>
 * <br>
 * [修改记录]<br>
 * 2017-05-04 10:48:27 创建 陶俊代码生成器<br>
 * 
 * @author JHSong
 * @version 1.00
 */
@Controller
@RequestMapping("/channel/export")
public class ExportController extends BaseController {

	@Autowired
	private CompanyService companyService;
	@Autowired
	private  SmsHistoryService smsHistoryService;
	private static Logger log = Logger.getLogger(ExportController.class);
	
	@RequestMapping("/smsSummaryExport")
	public void smsSummaryExport(SmsHistoryVo entity,HttpServletResponse response){
		
		Company company = companyService.selectById(entity.getMerchantId());
		if(null != company) {
			entity.setCompanyName(company.getCompanyName());
		}
		
		List<SmsHistory> smsHisList = new ArrayList<SmsHistory>();
		SmsHistoryDto smsHisDto = new SmsHistoryDto();
		smsHisDto.setMerchantId(entity.getMerchantId());
		smsHisDto.setCreateTimeBefore(entity.getCreateTimeBefore());
		smsHisDto.setCreateTimeAfter(entity.getCreateTimeAfter());
		smsHisDto.setSendStatus(SendStatusEnum.SUCCESS.getNo());
		smsHisList = smsHistoryService.selectListByDto(smsHisDto);
		
		ExportService.exportSmsHistory(smsHisList, entity, response);
	}
}
